﻿#region File Description
//-----------------------------------------------------------------------------
// HelpScreen.cs
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion
namespace ManagerGame.Screens
{
    class HelpScreen : MenuScreen
    {

        Texture2D gradientTexture;

        string message =
@"In this game you take the role of an aspiring entrepreneur
with a small amount of money to invest. You are expected to
expand your business and make a certain amount of cash in given turns.
START In the start menu you can alter the number of turns played 
and initial amount of money, or load a previously saved game.
MAIN GAME SCREEN In the main game screen you guide your 
entrepreneur around the city. Go to pub to purchase pubs 
and manage your pubs, to the shady-looking house to try your 
luck with escort services, or to the run-down building to take 
up a career in drug business. 
BUSINESS MANAGEMENT SCREEN Here you can either buy a new company 
or manage the companies you own. Alter the number of workers hired or 
the amount of salary you pay to one worker, or buy your workers a 
special treatment that varies by the type of the company.
MOVING AROUND Move the little green man around with arrow keys. 
In menu screens, move with up and down arrows, accept choices with 
space or enter. Return to game with space.
THE INFORMATION BAR The information bar displays your funds, number 
of turns, goals and the risk of getting caught by police. 
KEYS Move your entrepreneur around the city with arrow keys. In menu 
screens, use up and down arrows and choose menu items with ENTER. H brings 
out the help menu and ESC closes it. End the current turn with T.";

        MenuEntry menuEntry;
        SpriteFont font;
         /// <summary>
        /// Constructor.
        /// </summary>
        public HelpScreen()
            : base("Info")
        {

            // Create our menu entries.
            MenuEntry resumeGameMenuEntry = new MenuEntry("");

            menuEntry = resumeGameMenuEntry;
            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += OnCancel;

            // Add an entry to the menu.
            MenuEntries.Add(resumeGameMenuEntry);
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            font = content.Load<SpriteFont>("Fonts\\HelpScreenFont");
            gradientTexture = content.Load<Texture2D>("Images\\gradient");
        }

        /// <summary>
        /// Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
        /// </summary>
        protected new void OnCancel(object sender, PlayerIndexEventArgs e)
        {
            OnCancel(e.PlayerIndex);
        }

        /// <summary>
        /// Allows the screen the chance to position the menu entries. By default
        /// all menu entries are lined up in a vertical list, centered on the screen.
        /// </summary>
        protected new virtual void UpdateMenuEntryLocations()
        {
            // Make the menu slide into place during transitions, using a
            // power curve to make things look more interesting (this makes
            // the movement slow down as it nears the end).
            float transitionOffset = (float)Math.Pow(TransitionPosition, 2);

            // start at Y = 175; each X value is generated per entry
            Vector2 position = new Vector2(0f, 150f);

            // each entry is to be centered horizontally
            position.X = ScreenManager.GraphicsDevice.Viewport.Width / 2 - menuEntry.GetWidth(this) / 2;

            if (ScreenState == ScreenState.TransitionOn)
                position.X -= transitionOffset * 256;
            else
                position.X += transitionOffset * 512;

            // set the entry's position
            menuEntry.Position = position;

            // move down for the next entry the size of this entry
            position.Y += menuEntry.GetHeight(this);
            
        }


        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            UpdateMenuEntryLocations();
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            

            // Darken down any other screens that were drawn beneath the popup.
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            // Center the message text in the viewport.
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2 textSize = font.MeasureString(message);
            Vector2 textPosition = (viewportSize - textSize) / 2;

            // The background includes a border somewhat larger than the text itself.
            const int hPad = 32;
            const int vPad = 16;

            

            Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad,
                                                          (int)textPosition.Y - vPad,
                                                          (int)textSize.X + hPad * 2,
                                                          (int)textSize.Y + vPad * 2);

            // Fade the popup alpha during transitions.
            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();

            // Draw the background rectangle.
            spriteBatch.Draw(gradientTexture, backgroundRectangle, color);
            menuEntry.Draw(this, true, gameTime);
            // Draw the message box text.
            spriteBatch.DrawString(font, message, textPosition, color);

            spriteBatch.End();
        }
    }
}
